package com.sn.flink.batch

import org.apache.flink.api.scala.ExecutionEnvironment

object BatchWordCountScala {

  def main(args: Array[String]): Unit = {
    val inputPath = "d:/tmp/data"
    val outPath = "d:/tmp/results"

    val env = ExecutionEnvironment.getExecutionEnvironment

    val text = env.readTextFile(inputPath)

    import org.apache.flink.api.scala._
    val counts = text.flatMap(_.toLowerCase.split(" "))
      .filter(_.nonEmpty)
      .map(word => (word, 1))
      .groupBy(0)
      .sum(1)

    //setParallelism设置并行度
    counts.writeAsCsv(outPath, "\n", " ").setParallelism(1)
    env.execute("batch word count")
  }

}
